<template>
  <div class="group-store">
    <div class="table-title">
      <el-input v-model="searchData.MultiSearch" style="width:220px;" placeholder="姓名、电话、订单号或房间号"></el-input>
      <el-select v-model="searchData.HotelId" placeholder="请选择酒店" style="position: relative;top: 1px;">
  			<el-option :label="'全部'" :value="0"></el-option>
  			<el-option v-for="m in HotelList" :label="m.Name" :value="m.Id" :key="m.Id"></el-option>
  		</el-select>
      <el-select v-model="searchData.Status" placeholder="请选择状态" style="position: relative;top: 1px;">
				<el-option :label="'全部状态'" :value="-1"></el-option>
				<el-option :label="'已预订'" :value="'0'"></el-option>
				<el-option :label="'已入住'" :value="'1'"></el-option>
				<el-option :label="'已退房'" :value="'3'"></el-option>
				<el-option :label="'已取消'" :value="'5'"></el-option>
			</el-select>
      <el-select v-model="searchData.FromChannel" placeholder="渠道类型" @change="getFromChannel1(searchData.FromChannel)">
        <el-option :label="'全部渠道'" :value="0"></el-option>
        <el-option
          v-for="m in ChannelList"
          :label="m.Name"
          :value="parseInt(m.Code)"
          :key="m.Code">
        </el-option>
      </el-select>
      <el-select v-model="searchData.TravelAgency" placeholder="渠道商" filterable v-if="searchData.FromChannel==7||searchData.FromChannel==8">
        <el-option
          label="全部"
          :value="0"
          :key="0">
        </el-option>
        <el-option
          v-for="m in ChannelChildList"
          :label="m.Name"
          :value="parseInt(m.Code)"
          :key="m.Code">
        </el-option>
      </el-select>
      <div style="margin-top:20px">
        <el-radio @change="getDate()" v-model="searchData.DateType" label="0">预定日期</el-radio>
        <el-radio @change="getDate()" v-model="searchData.DateType" label="1">入住日期</el-radio>
        <el-radio @change="getDate()" v-model="searchData.DateType" label="2">离店日期</el-radio>
        <el-date-picker
          v-model="dateTime"
          v-if="searchData.DateType"
          type="daterange"
          :editable="false"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="getDate">
        </el-date-picker>
  			<el-button type="primary" @click="initList" data-auth="bloc_allorder_query">查询</el-button>
  			<el-button type="primary" :disabled="!listData.length" @click="handleExcel" data-auth="bloc_allorder_export">导出</el-button>
      </div>
    </div>
    <div class="table-content">
      <el-table
        border
        :data="listData"
        style="width: 100%">
        <el-table-column
          label="酒店名称"
          prop="HotelName">
        </el-table-column>
        <el-table-column
          label="客人姓名"
          prop="ContactName">
        </el-table-column>
        <el-table-column
          label="电话">
          <template slot-scope="scope">
            <span>{{scope.row.ContactPhone||''}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="房间信息">
          <template slot-scope="scope">
            <span>{{scope.row.RoomCategoryName||''}}</span>
            <p>({{scope.row.RoomNo||''}})</p>
          </template>
        </el-table-column>
        <el-table-column
          label="入离时间">
          <template slot-scope="scope">
            <span>{{scope.row.CheckInDate.slice(5,10)}}至{{scope.row.CheckOutDate.slice(5,10)}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="金额"
          prop="HotelAllAmount">
          <template slot-scope="scope">
            <span>￥{{scope.row.HotelAllAmount||''}}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="渠道类型"
          prop="FromChannelName">
        </el-table-column>
				<el-table-column
          label="支付状态"
          prop="PaymentStatusName">
        </el-table-column>
				<el-table-column
          label="订单状态"
          prop="HotelOrderStatusName">
        </el-table-column>
        <el-table-column label="操作" width="80px">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleShow(scope.$index, scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="table-page">
			<el-pagination
			  background
				@size-change="changePage"
      	@current-change="getList"
      	:current-page.sync="searchData.pageIndex"
      	:page-sizes="[100, 200, 300, 400]"
			  layout="total,prev, pager, next"
			  :total="pageTotal">
			</el-pagination>
    </div>
    <time-line :showInfo="showInfo" :formData="formData" :title="'集团订单日志'" ref="tim"></time-line>

    <el-dialog
      :title="'订单详情'"
      :visible.sync="orderInfo"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      width="850px"
      center>
      <div class="orderinfo-div">
        <div class="orderinfo-title">基本信息</div>
        <span>联系人： {{orderInfoData.ContactName}} </span>
        <span :title="orderInfoData.PhoneAttribution">联系电话： {{orderInfoData.ContactPhone}}({{orderInfoData.PhoneAttribution}}) </span>
        <span>销售员： {{getSaleMan(orderInfoData.SalesmanId)}}</span>
        <span>支付类型： {{orderInfoData.PaymentModeName}}</span>
        <span>渠道来源： {{orderInfoData.FromChannelName}}</span>
        <span v-if="!!orderInfoData.TravelAgencyName">渠道商： {{orderInfoData.TravelAgencyName}}</span>
      </div>
      <div class="orderinfo-div">
        <div class="orderinfo-title">
          预定信息<span style="font-size:14px">（订单号：{{orderInfoData.OrderSerialid}}）</span>
        </div>
        <template  v-for="m in orderInfoData.RoomList">
          <span>入住：{{m.CheckInDate.split('T')[0]}}</span>
          <span>离店：{{m.CheckOutDate.split('T')[0]}}</span>
          <span>共{{getAlldate(m.CheckInDate,m.CheckOutDate).length-1}}晚</span>
          <span>房型：{{m.RoomCategoryName}}<i class="type" :class="{'room-book':m.Status===0,'room-in':m.Status===1}">{{orderTypeList[m.Status]}}</i></span>
          <span>房间数：{{m.RoomCount}}</span>
          <span>价格：<b>{{m.AllAmount}}元</b></span>
          <p v-for="n in m.Roomers">
            <span>入住人姓名： {{n.Name}}</span>
            <span>入住人{{cerList[n.CertType]}}：{{n.CertNo}}</span>
          </p>
        </template>
        <p v-for="m in orderInfoData.SingleProductOrders">
          <span>商品：{{m.ProductName}}（{{m.UnitPrice}}/{{m.Unit}}）</span>
          <span>数量：{{m.Quantity}}{{m.Unit}}</span>
          <span>价格：<b>{{m.AllAmount}}元</b></span>
        </p>
      </div>
      <div class="orderinfo-div">
        <div class="orderinfo-title">
          收银信息
        </div>
        <span>订单总额: <b>¥{{orderInfoData.AllAmount}}</b></span>
        <span>已收款：<b>¥{{orderInfoData.PaidAmount}}</b></span>
        <span>需补交：<b>¥{{orderInfoData.RestAmount}}</b></span>
        <span @click="getpriceData" style="cursor:pointer;color: #399be6;margin-left:10px;float: right;text-align:right">财务明细</span>
        <div style="padding:10px 20px 0px 0px;float: left;">
          <el-dropdown trigger="hover" placement="top" @command="addPriceInfo">
            <span class="el-dropdown-link">添加款项</span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :command="{type:1,name:'收款'}">收款</el-dropdown-item>
              <el-dropdown-item :command="{type:2,name:'商品'}">商品</el-dropdown-item>
              <el-dropdown-item :command="{type:3,name:'收押金'}">收押金</el-dropdown-item>
              <el-dropdown-item :command="{type:4,name:'退款'}">退款</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <el-table
          :data="tableData"
          style="width: 95%;margin:5px auto;max-height: 200px;overflow: auto;"
          v-show="tableShow">
          <el-table-column
            prop="CashierItem"
            label="项目">
            <template slot-scope="scope">
              {{CashierItem[scope.row.CashierItem]}}
            </template>
          </el-table-column>
          </el-table-column>
          <el-table-column
            prop="Amount"
            label="收款">
          </el-table-column>
          <el-table-column
            label="支付方式"
            prop="CashierChannelDes">
          </el-table-column>
          <el-table-column
            prop="Remark"
            label="财务备注">
          </el-table-column>
          <el-table-column
            prop="OperatorTimeView"
            label="操作时间">
            <template slot-scope="scope">
              <template v-if="!!scope.row.OperatorTimeView">{{scope.row.OperatorTimeView}}</template>
            </template>
          </el-table-column>
          <el-table-column
            prop="OperatorName"
            label="操作人">
          </el-table-column>
          <el-table-column
            label="操作"
            class="delete-td">
            <template slot-scope="scope">
              <span @click="deletePriceInfo(scope.row)" v-if="scope.row.IsValid" style="color:rgb(57, 155, 230);cursor:pointer;">删除</span>
              <span v-else style="color:red">已删除</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="orderinfo-div">
        <div class="orderinfo-title">
          备注
        </div>
        <p style="padding:0 15px;">{{orderInfoData.Remark}}</p>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="warning" size="mini" round @click.stop="() => {formData.orderSerialid=orderInfoData.OrderSerialid;$refs.tim.toggleDiolag()}">订单日志</el-button>
      </span>
    </el-dialog>

  </div>
</template>
<script>
  export default {
    data () {
      let _this=this;
      return {
        showInfo:true,
        formData:{
          orderSerialid : ''
        },
        HotelId:0,
        pageTotal:0,
        dateTime:[],
        searchData:{
          HotelId:0,
          Status:-1,
          OrgId:JSON.parse(sessionStorage.getItem('nowmenu')).Id,
					MultiSearch:'',
          pageIndex:1,
          pageSize:10,
          StartDate:'',
          EndDate:'',
          FromChannel:0,
          TravelAgency:0,
          DateType:'0'
        },
        HotelList:[],
				radio:1,
        CancelReason:'',
        CashierItem:{1:'房费',2:'商品',3:'押金',4:'退款'},
        paymentList:{1:'待支付',2:'支付中',3:'已支付'},
        cerList:{1:'身份证',2:'护照',3:'军官证',4:'通行证',5:'其他'},
        orderTypeList:['已预订','已入住','部分入住','已退房','部分退房','已取消'],
        orderCount:{assign:0,checkin:0,checkout:0,in:0},
        roomoutShow:false,
        roominShow:false,
        tableShow:false,
        priceShow:false,
        roomShow:false,
        orderInfo:false,
        deleteOrderShow:false,
        dialogTitle:'',
        priceTitle:'',
        dialogData:[],
        RoomCategoryIds:[],
        SalesmanList:[],
        ChannelList:[],
        ChannelChildList:[],
        orderInfoData:{},
        orderSerialid:'',
        OrderAction:1,
        priceForm:{
          Amount:'',
          Remark:'',
          CashierChannel:'',
        },
        pricerules:{
          Amount: [
            { required: true, message: '请输入金额', trigger: 'blur' },
          ],
          Remark: [
            { required: false, message: '', trigger: 'blur' },
          ],
          CashierChannel: [
            { required: true, message: '请选择支付方式', trigger: 'change' },
          ],
        },
        roominData:[],
        roomoutData:{
          OrderSerialid:'',
          HotelOrderIds:[],
          Remark:''
        },
        ruleForm: {
          ContactName: '',
          ContactPhone: '',
          FromChannel: '',
          SalesmanName: '',
          Remark:'',
          AllAmount:'',
          SellingPriceAmount:'',
          SalesmanId:0,
					PaymentMode:''
        },
        rules: {
          ContactName: [
            { required: true, message: '请输入联系人', trigger: 'blur' },
          ],
          ContactPhone: [],
          FromChannel: [
            { required: true, message: '请选择来源渠道', trigger: 'change' },
          ],
          TravelAgency: [
            { required: true, message: '请选择渠道商', trigger: 'change' },
          ],
          SalesmanId: [],
          PaymentMode: [
            { required: true,type:'number',message: '请选择支付类型', trigger: 'change' },
          ]
        },
        weekday:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],
        startOptions: {
          disabledDate(time) {
            if(_this.OrderAction===2){
              return Date.now()>(time.getTime()+ 3600 * 1000 * 24 * 1)||Date.now()<time.getTime();
            }else if(_this.OrderAction===0){
              return false;
            }
            else{
              return Date.now()>(time.getTime()+ 3600 * 1000 * 24 * 1);
            }
          }
        },
        endOptions: {
          disabledDate(time) {
            if(_this.OrderAction===2){
              return Date.now()>(time.getTime()+ 3600 * 1000 * 24 * 1);
            }else if(_this.OrderAction===0){
              return false;
            }else{
              return Date.now()>time.getTime();
            }
          }
        },
        roomNumData:[],
        roomRowData:[
          {roomName:'101',roomId:'6',roomList:[
            {roomIn:0,price:'150'},
          ]}
        ],
        roomRowFormatData:[],
        orderData:[
          {room:'001',roomNum:'101',date:this.$format('yyyy-MM-dd',new Date()),name:'客户来源',day:1,type:'订单状态',personName:'客户姓名1'},
        ],
        nowDate: this.$format('yyyy-MM-dd',new Date()),
        selectedRoom:[],
        selectedCol:[],
        showCardList:[],
        ProductList:[],
        tableData:[],
        CashierChannelList:[],
        listData:[],
        setRoomShow:false,
        HotelOrderData:[],
        setRoomData:[],
      }
    },
    created(){
      this.$ajax.GetStoreList().then(res=>{
        if(res.Success&&res.Data){
          this.HotelList=res.Data
        }
      })
      this.$ajax.PayTypes().then(res=>{
        if(res.Success){
          this.CashierChannelList=res.Data;
        }
      })
      this.$ajax.GetUserListByOrgId({orgId:23}).then(res=>{
        if(res.Success){
          this.SalesmanList=res.Data;
          this.$ajax.Channels().then(res=>{
            if(res.Success){
              this.ChannelList=res.Data;
            }
          })
        }
      })
      this.initList();
    },
    methods:{
			getDate(date){
        if(!date){
          this.searchData.StartDate=''
          this.searchData.EndDate=''
          this.dateTime=[];
          return;
        }
        if(this.searchData.StartDate===this.$format('yyyy-MM-dd',new Date(date[0])) && this.searchData.EndDate===this.$format('yyyy-MM-dd',new Date(date[1])))return;
        this.searchData.StartDate=this.$format('yyyy-MM-dd',new Date(date[0]))
        this.searchData.EndDate=this.$format('yyyy-MM-dd',new Date(date[1]))
      },
      getSaleMan(id){
        let name=''
        this.SalesmanList.forEach(val=>{
          if(val.Id==id){
            name=val.Name
          }
        })
        return name
      },
      initRoom(){
        this.roomoutShow=false;
        this.roominShow=false;
        this.tableShow=false;
        this.priceShow=false;
        this.roomShow=false;
        this.orderInfo=false;
        this.deleteOrderShow=false;
        this.getList();
      },
      initList(){
        this.searchData.pageIndex=1;
        this.roomShow=false;
        this.roomColShow=false;
        this.getList();
      },
      changePage(size){
        this.searchData.pageIndex=1;
        this.searchData.pageSize=size;
        this.getList();
      },
      getList(){
        this.$ajax.GetHotelOrderByPage(this.searchData).then(res=>{
          if(res.Success){
            this.listData=res.Data.PagedData;
            this.pageTotal=res.Data.TotalCount;
          }
        })
      },
      handleExcel(){
        let data=_.cloneDeep(this.searchData);
        data=this.$urlEncode(data);
        window.open(this.$api.GetHotelOrderToExcel+'?'+data);
			},
      resetForm(formName) {
        if(!this.$refs[formName]){return};
        this.$refs[formName].resetFields();
      },
			getDays(index){
        return new Date(new Date(this.nowDate).getTime() + 3600 * 1000 * 24 * index).getDay();
      },
      getFormatDay(index){
        return new Date(new Date(this.nowDate).getTime() + 3600 * 1000 * 24 * index);
      },
      isToday(index){
        return this.$format('MM-dd',new Date())===this.$format('MM-dd',this.getFormatDay(index));
      },
      getStartEnd(arr){

      },
      getAlldate(start,end){
        let bd = new Date(start),be = new Date(end);
        let bdTime = bd.getTime(), beTime = be.getTime(),timeDiff = beTime - bdTime;
        let dArr = [];
        for(var i=0; i<= timeDiff; i+=86400000){
          var ds = this.$format('yyyy-MM-dd',new Date(bdTime+i));
          dArr.push(ds)
        }
        return dArr
      },
			showBtn(type){
        let now=this.$format('yyyy-MM-dd',new Date());
        let yestoday=this.$format('yyyy-MM-dd',new Date(new Date(this.nowDate).getTime() - 3600 * 1000 * 24));
        switch (type) {
          case 0:
            return this.selectedRoom.every((val)=>{return val.date>=now})
            break;
          case 1:
            return this.selectedRoom.some((val)=>{return val.date==now||val.date==yestoday})
            break;
          case -1:
            return this.selectedRoom.some((val)=>{return val.date<now})
            break;
          default:
            return true
        }
      },
      continueDays(arr_days) {
        // 先排序，然后转时间戳
        let days = arr_days.sort().map((d, i) => {
          let dt = new Date(d)
          dt.setDate(dt.getDate() + 4 - i) // 处理为相同日期

          // 抹去 时 分 秒 毫秒
          dt.setHours(0)
          dt.setMinutes(0)
          dt.setSeconds(0)
          dt.setMilliseconds(0)

          return +dt
        })

        let ret = true

        days.forEach(d => {
          if (days[0] !== d) {
            ret = false
          }
        })

        return ret
      },
      roomIn(){
        let ret = false;
        _.map(this.showCardList,(val)=>{
          val.dateList=[]
          _.map(this.selectedRoom,(room)=>{
            if(val.roomNum===room.roomNum){
              val.dateList.push(room.date)
            }
          })
          val.dateList=val.dateList.sort();
          if(!val.dateList.some(val=>{return val.indexOf(this.$format('yyyy-MM-dd',new Date()))>=0})){
            ret=true;
          }
        })
        if(ret||!this.showCardList.every(val=>{return this.continueDays(val.dateList)})){
          this.$confirm('未来日期不可直接入住', {
            showConfirmButton:false,
            showCancelButton:false,
            callback:()=>{},
            type:'warning'
          })
          return;
        }
        this.clearRuleForm();
        this.dialogData=this.getDialogRoomData(_.sortBy(this.selectedRoom, ['roomNum', 'date']));
        this.dialogTitle='直接入住';
        this.OrderAction=2;
        this.showAddRoom();
      },
      getDialogRoomData(data){
        let finData=[];
        let obj={};
        let getdd=(date)=>{return this.$format('yyyy-MM-dd',new Date(new Date(date).getTime() - 3600 * 1000 * 24))};
        let getend=(date)=>{return this.$format('yyyy-MM-dd',new Date(new Date(date).getTime() + 3600 * 1000 * 24))};
        _.map(data,(val)=>{
          val.startDate=val.CheckInDate;
          val.endDate=val.CheckOutDate;
          val.roomId=val.RoomCategoryId;
          val.PolicyId=val.RoomCategoryPolicyId;
          finData=finData.concat(val);
        })
        return finData;
      },
      roomBook(){
        this.clearRuleForm();
        this.ruleForm=this.orderInfoData;
        this.dialogData=this.getDialogRoomData(this.ruleForm.RoomList);
        this.dialogTitle='修改订单';
        this.OrderAction=1;
        this.$ajax.GetRoomCategoryList({hotelId:this.orderInfoData.HotelId}).then(res=>{
          if(res.Success&&res.Data){
            this.roomNumData=[];
            _.map(res.Data,val=>{
              this.roomNumData.push({
                roomName:val.Name,
                isopen:true,
                roomId:val.Id,
                roomData:val.RoomNos
              })
            })
            _.map(this.dialogData,val=>{
              console.log(val)
              this.$ajax.getpolicylist({roomCategoryId:val.RoomCategoryId,hotelId:val.HotelId}).then(res=>{
                if(res.Success){
                  val.CategoryList=res.Data;
                }
              })
              console.log(val);
              this.showAddRoom();
            })
          }
        })
      },
      getFromChannel1(id){
        this.ruleForm.TravelAgency='';
        if(id==7||id==8){
          _.map(this.ChannelList,val=>{
            if(val.Code==id){
              this.ChannelChildList=val.Childs
            }
          })
        }else{
          this.ChannelChildList=[];
        }
      },
      showAddRoom(){
        this.tableData=[];
        this.roomShow=true;
      },
      clearRuleForm(){
        this.ProductList=[];
        this.ruleForm={
          ContactName: '',
          ContactPhone: '',
          TravelAgency: '',
          SalesmanName: '',
          Remark:'',
          AllAmount:'',
          SellingPriceAmount:'',
          PaymentMode:3,
          FromChannel: !!this.ChannelList[0]?parseInt(this.ChannelList[0].Code):'',
          SalesmanId:0
        }
        !!this.$refs['ruleForm']?this.$refs['ruleForm'].resetFields():'';
      },
      getMroomData(val,index){
        this.$ajax.getpolicylist({roomCategoryId:val.roomId,hotelId:val.HotelId}).then(res=>{
          if(res.Success){
            val.PolicyId='';
            val.CategoryList=res.Data;
            this.$set(this.dialogData,index,val);
          }
        })
      },
      getRoomId(m,val){
        _.map(m.roomData,value=>{
          if(value.RoomName==val){
            m.Id=value.RoomId
          }
        })
      },
      getendDate(m,index){
        m.endDate=this.$format('yyyy-MM-dd',new Date(new Date(m.startDate).getTime() + 3600 * 1000 * 24))+' 12:00:00'
        let data={
          HotelOrderId:m.HotelOrderId||0,
          CheckInTime:m.startDate,
          CheckOutTime:m.endDate,
          RoomCategoryId:m.roomId,
          HotelId:this.HotelId
        }
        this.$ajax.GetAvailableRooms(data).then(res=>{
          if(res.Success){
            if(!res.Data.some(item=>{return item.RoomName===m.roomNum})){
              m.roomNum='';
            }
            m.roomData=res.Data;
            this.$set(this.dialogData,index,m)
          }
        })
        this.getMroomPrcie(m);
      },
      getMroomPrcie(m){
        if(!m.PolicyId)return;
        if(m.endDate< m.startDate){
          m.startDate=this.$format('yyyy-MM-dd',new Date(new Date(m.endDate).getTime() - 3600 * 1000 * 24))+' 12:00:00'
        }
        let data={roomCategoryId:m.roomId,policyConfigId:m.PolicyId,rooms:1,date:m.startDate.split(' ')[0],days:this.getAlldate(m.startDate,m.endDate).length-1};
        this.$ajax.singlepolicyprice(data).then(res=>{
          if(res.Success){
            this.ruleForm.AllAmount+=res.Data-m.AllAmount;
            this.ruleForm.SellingPriceAmount+=res.Data-m.AllAmount;
            m.AllAmount=res.Data;
            m.PolicyPriceAmount=res.Data;
          }
        })
      },
      GetSingleProductByType(data){
        data.ProductId="";
        data.UnitPrice="";
        data.AllAmount=0;
        data.SellingPriceAmount=0;
        this.getAllAmount();
        this.$ajax.GetSingleProductByType({type:data.ProductType,hotelId:this.HotelId}).then(res=>{
          if(res.Success){
            data.ProductNameList=res.Data;
          }
        })
      },
      getFromChannel1(id){
        this.ruleForm.TravelAgency='';
        if(id==7||id==8){
          _.map(this.ChannelList,val=>{
            if(val.Code==id){
              this.ChannelChildList=val.Childs
            }
          })
        }else{
          this.ChannelChildList=[];
        }
      },
      getUnitPrice(data){
        data.UnitPrice='';
        _.map(data.ProductNameList,val=>{
          if(val.Id===data.ProductId){
            data.UnitPrice=val.UnitPrice;
            data.AllAmount=data.UnitPrice*data.Quantity;
            data.SellingPriceAmount=data.UnitPrice*data.Quantity;
            data.ProductName=val.Name;
            data.Unit=val.Unit;
          }
        })
        this.getAllAmount();
      },
      getAllAmount(){
        this.ruleForm.AllAmount=0;
        this.ruleForm.SellingPriceAmount=0;
        _.map(this.dialogData,val=>{
          this.ruleForm.AllAmount+=parseFloat(val.AllAmount);
          this.ruleForm.SellingPriceAmount+=parseFloat(val.PolicyPriceAmount);
        })
        _.map(this.ProductList,val=>{
          this.ruleForm.AllAmount+=parseFloat(val.AllAmount);
          this.ruleForm.SellingPriceAmount+=parseFloat(val.SellingPriceAmount);
        })
      },
      submitOrder(){
        this.$refs['ruleForm'].validate((valid) => {
          if (valid) {
              let data={
                OrderAction: this.OrderAction,
                RoomList: [],
                ProductList: [],
                ...this.ruleForm
              }
              data.RoomList=[];
              _.map(this.dialogData,val=>{
                console.log(val);
                data.RoomList.push({
                  "Id":this.OrderAction===0?val.HotelOrderId:0,
                  "RoomCategoryName": val.RoomCategoryName,
                  "RoomCategoryPolicyId": val.PolicyId,
                  HotelId: this.ruleForm.HotelId,
                  HotelName: this.ruleForm.HotelName,
                  "RoomCategoryId": val.roomId,
                  "RoomId":val.Id,
                  "CheckInDate": val.startDate,
                  "CheckOutDate": val.endDate,
                  "Days": this.getAlldate(val.startDate,val.endDate).length-1,
                  PolicyPriceAmount:val.PolicyPriceAmount,
                  "AllAmount": val.AllAmount,
                  RoomCount:val.RoomCount
                })
              })
              _.map(this.ProductList,val=>{
                data.ProductList.push({
                  "Id":val.Id,
                  ...val
                })
              })
              this.$ajax.ChangeBlocOrder(data).then(res=>{
                if(res.Success){
                  this.$message.success('已修改!');
                  this.initList();
                  this.showOrder(res.Data);
                }
              })
              }
            }
          )
      },
      showOrder(id){
        this.orderSerialid=id;
        this.$ajax.GetBlocOrderDetail({OrderSerialid:this.orderSerialid}).then(res=>{
          if(res.Success){
            this.orderInfoData=res.Data;
            this.orderInfo=true;
            this.tableShow=false;
            if(this.roomoutShow){
              this.roomoutShowBtn()
            }else if(this.roominShow){
              this.roominShowBtn()
            }else{
              this.roomoutShow=false;
              this.roominShow=false;
            }
          }
        })
      },
      deleteRoomPro(data,index){
        this[data].splice(index,1);
        this.getAllAmount();
      },
      getpriceData(){
        if(!this.tableShow){
          this.tableData=[];
          this.$ajax.getcashierrecords({orderSerialid:this.orderSerialid}).then(res=>{
            if(res.Success){
              this.tableData=res.Data;
              this.tableShow=true;
            }
          })
        }else{
          this.tableShow=false;
        }
      },
      addPriceInfo(command){
        this.priceTitle=command.name;
        this.priceForm={
          Amount:'',
          Remark:'',
          CashierChannel:'',
          CashierItem:command.type,
          OrderSerialid:this.orderSerialid
        }
        this.priceShow=true;
      },
      addPriceRoomIn(formName){
        this.tableData.push(this.priceForm);
        this.priceShow=false;
        this.tableShow=true;
      },
      addPriceBtn(formName){
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$ajax.savecashierrecord(this.priceForm).then(res=>{
              if(res.Success){
                this.$message.success('收款成功!');
                this.$refs[formName].resetFields();
                this.priceShow=false;
                this.tableShow=false;
                this.showOrder(this.orderSerialid);
                this.getpriceData();
              }
            })
          } else {
            return false;
          }
        });
      },
      deletePriceInfo(data){
        this.$confirm(`确认删除该${this.CashierItem[data.CashierItem]}记录？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
          center: true
        }).then(() => {
          this.$ajax.deleteordercashierrecord({Id:data.Id,Item:data.CashierItem}).then(res=>{
            if(res.Success){
              this.$message({
                type: 'success',
                message: '已删除!'
              });
              this.showOrder(this.orderSerialid);
              this.tableShow=false;
              this.getpriceData();
            }
          })
        }).catch(() => {
        });
      },
      deleteOrderShowBtn(){
        this.priceForm={
          Amount:'',
          Remark:'',
          CashierChannel:'',
          CashierItem:4,
          OrderSerialid:this.orderSerialid
        }
        this.deleteOrderShow=true;
      },
      deleteOrder(formName){
        if(!this.CancelReason){
          this.$message.error('请选择取消原因');
          return
        }
        let data={
          orderSerialid:this.orderSerialid,
          CancelReason:this.CancelReason
        }
        if(this.radio===0){
          this.$refs[formName].validate((valid) => {
            if (valid) {
              this.$ajax.savecashierrecord(this.priceForm).then(res=>{
                if(res.Success){
                  this.$ajax.CancelOrder(data).then(res=>{
                    if(res.Success){
                      this.$message({
                        type: 'success',
                        message: '已取消!'
                      });
                      this.deleteOrderShow=false;
                      this.orderInfo=false;
                      this.initRoom();
                    }
                  })
                }
              })
            }else {
              return false;
            }
          });
        }else{
          this.$ajax.CancelOrder(data).then(res=>{
            if(res.Success){
              this.$message({
                type: 'success',
                message: '已取消!'
              });
              this.deleteOrderShow=false;
              this.orderInfo=false;
              this.initRoom();
            }
          })
        }
      },
			handleShow(index,data){
        this.showOrder(data.OrderSerialid);
        this.HotelId=data.HotelId;
			},
      setRoom(id){
        this.orderSerialid=id;
        this.$ajax.GetOrderForSetRoom({orderSerialId:id}).then(res=>{
          if(res.Success){
            this.setRoomData=res.Data.map(val=>{
              val.roomType=0;
              val.checkList=[];
              return val;
            })
            this.setcheck(0);
            this.setRoomShow=true;
          }
        })
      },
      setcheck(type){
        this.setRoomData.forEach(val=>{
          val.checkList=[];
          val.RoomList.forEach(item=>{
            switch (type){
              case 1:
              if(item.HotelOrderId>0&&item.IsDirty){
                val.checkList.push(item.RoomId)
              }
              break;
              case 2:
              if(item.HotelOrderId>0&&!item.IsDirty){
                val.checkList.push(item.RoomId)
              }
              break;
              default:
              if(item.HotelOrderId>0){
                val.checkList.push(item.RoomId)
              }
              break;
            }
          })
        })
      },
      getcheckList(val,count){
        if(val.length>count){
          val=val.splice(count,1);
        }
      },
      OrderSetRoom(){
        let data={
          OrderSerialId:this.orderSerialid,
          RoomIds:[]
        }
        this.setRoomData.forEach(val=>{
          data.RoomIds.push(...val.checkList);
        })
        this.$ajax.OrderSetRoom(data).then(res=>{
          if(res.Success){
            this.$message.success('分房成功!');
            this.setRoomShow=false;
            this.initRoom();
          }
        })
      },
    }
  }
</script>
